home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Interfaces&Libraries / Universal / Interfaces / PInterfaces / Threads.p < prev    next >
Encoding:
Text File  |  1998-08-17  |  8.5 KB  |  274 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        Threads.p
  3.  
  4.      Contains:    Thread Manager Interfaces.
  5.  
  6.      Version:    Technology:    Mac OS 8
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1991-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. }
  17. {$IFC UNDEFINED UsingIncludes}
  18. {$SETC UsingIncludes := 0}
  19. {$ENDC}
  20.  
  21. {$IFC NOT UsingIncludes}
  22.  UNIT Threads;
  23.  INTERFACE
  24. {$ENDC}
  25.  
  26. {$IFC UNDEFINED __THREADS__}
  27. {$SETC __THREADS__ := 1}
  28.  
  29. {$I+}
  30. {$SETC ThreadsIncludes := UsingIncludes}
  31. {$SETC UsingIncludes := 1}
  32.  
  33. {$IFC UNDEFINED __MACTYPES__}
  34. {$I MacTypes.p}
  35. {$ENDC}
  36. {$IFC UNDEFINED __MIXEDMODE__}
  37. {$I MixedMode.p}
  38. {$ENDC}
  39. {$IFC UNDEFINED __ERRORS__}
  40. {$I Errors.p}
  41. {$ENDC}
  42.  
  43.  
  44. {$PUSH}
  45. {$ALIGN MAC68K}
  46. {$LibExport+}
  47.  
  48. { Thread states }
  49.  
  50. TYPE
  51.     ThreadState                            = UInt16;
  52.  
  53. CONST
  54.     kReadyThreadState            = 0;
  55.     kStoppedThreadState            = 1;
  56.     kRunningThreadState            = 2;
  57.  
  58. { Error codes have been meoved to Errors.(pah) }
  59. { Thread environment characteristics }
  60.  
  61. TYPE
  62.     ThreadTaskRef                        = Ptr;
  63. { Thread characteristics }
  64.     ThreadStyle                            = UInt32;
  65.  
  66. CONST
  67.     kCooperativeThread            = $00000001;
  68.     kPreemptiveThread            = $00000002;
  69.  
  70. { Thread identifiers }
  71.  
  72. TYPE
  73.     ThreadID                            = UInt32;
  74.  
  75. CONST
  76.     kNoThreadID                    = 0;
  77.     kCurrentThreadID            = 1;
  78.     kApplicationThreadID        = 2;
  79.  
  80. { Options when creating a thread }
  81.  
  82. TYPE
  83.     ThreadOptions                        = UInt32;
  84.  
  85. CONST
  86.     kNewSuspend                    = $01;
  87.     kUsePremadeThread            = $02;
  88.     kCreateIfNeeded                = $04;
  89.     kFPUNotNeeded                = $08;
  90.     kExactMatchThread            = $10;
  91.  
  92. { Information supplied to the custom scheduler }
  93.  
  94. TYPE
  95.     SchedulerInfoRecPtr = ^SchedulerInfoRec;
  96.     SchedulerInfoRec = RECORD
  97.         InfoRecSize:            UInt32;
  98.         CurrentThreadID:        ThreadID;
  99.         SuggestedThreadID:        ThreadID;
  100.         InterruptedCoopThreadID: ThreadID;
  101.     END;
  102.  
  103.  
  104. {$IFC TARGET_CPU_68K AND TARGET_RT_MAC_CFM }
  105. {
  106.     The following UniversalProcPtrs are for CFM-68k compatiblity with
  107.     the implementation of the Thread Manager.
  108. }
  109.     ThreadEntryProcPtr                    = UniversalProcPtr;
  110.     ThreadSchedulerProcPtr                = UniversalProcPtr;
  111.     ThreadSwitchProcPtr                    = UniversalProcPtr;
  112.     ThreadTerminationProcPtr            = UniversalProcPtr;
  113.     DebuggerNewThreadProcPtr            = UniversalProcPtr;
  114.     DebuggerDisposeThreadProcPtr        = UniversalProcPtr;
  115.     DebuggerThreadSchedulerProcPtr        = UniversalProcPtr;
  116. {$ELSEC}
  117. {
  118.     The following ProcPtrs cannot be interchanged with UniversalProcPtrs because
  119.     of differences between 680x0 and PowerPC runtime architectures with regard to
  120.     the implementation of the Thread Manager.
  121.  }
  122. { Prototype for thread's entry (main) routine }
  123.     voidPtr                                = Ptr;
  124. {$IFC TYPED_FUNCTION_POINTERS}
  125.     ThreadEntryProcPtr = FUNCTION(threadParam: UNIV Ptr): voidPtr;
  126. {$ELSEC}
  127.     ThreadEntryProcPtr = ProcPtr;
  128. {$ENDC}
  129.  
  130. { Prototype for custom thread scheduler routine }
  131. {$IFC TYPED_FUNCTION_POINTERS}
  132.     ThreadSchedulerProcPtr = FUNCTION(schedulerInfo: SchedulerInfoRecPtr): ThreadID;
  133. {$ELSEC}
  134.     ThreadSchedulerProcPtr = ProcPtr;
  135. {$ENDC}
  136.  
  137. { Prototype for custom thread switcher routine }
  138. {$IFC TYPED_FUNCTION_POINTERS}
  139.     ThreadSwitchProcPtr = PROCEDURE(threadBeingSwitched: ThreadID; switchProcParam: UNIV Ptr);
  140. {$ELSEC}
  141.     ThreadSwitchProcPtr = ProcPtr;
  142. {$ENDC}
  143.  
  144. { Prototype for thread termination notification routine }
  145. {$IFC TYPED_FUNCTION_POINTERS}
  146.     ThreadTerminationProcPtr = PROCEDURE(threadTerminated: ThreadID; terminationProcParam: UNIV Ptr);
  147. {$ELSEC}
  148.     ThreadTerminationProcPtr = ProcPtr;
  149. {$ENDC}
  150.  
  151. { Prototype for debugger NewThread notification }
  152. {$IFC TYPED_FUNCTION_POINTERS}
  153.     DebuggerNewThreadProcPtr = PROCEDURE(threadCreated: ThreadID);
  154. {$ELSEC}
  155.     DebuggerNewThreadProcPtr = ProcPtr;
  156. {$ENDC}
  157.  
  158. { Prototype for debugger DisposeThread notification }
  159. {$IFC TYPED_FUNCTION_POINTERS}
  160.     DebuggerDisposeThreadProcPtr = PROCEDURE(threadDeleted: ThreadID);
  161. {$ELSEC}
  162.     DebuggerDisposeThreadProcPtr = ProcPtr;
  163. {$ENDC}
  164.  
  165. { Prototype for debugger schedule notification }
  166. {$IFC TYPED_FUNCTION_POINTERS}
  167.     DebuggerThreadSchedulerProcPtr = FUNCTION(schedulerInfo: SchedulerInfoRecPtr): ThreadID;
  168. {$ELSEC}
  169.     DebuggerThreadSchedulerProcPtr = ProcPtr;
  170. {$ENDC}
  171.  
  172. {$ENDC}
  173.  
  174.  
  175. { Thread Manager routines }
  176. FUNCTION CreateThreadPool(threadStyle: ThreadStyle; numToCreate: INTEGER; stackSize: Size): OSErr;
  177.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  178.     INLINE $303C, $0501, $ABF2;
  179.     {$ENDC}
  180. FUNCTION GetFreeThreadCount(threadStyle: ThreadStyle; VAR freeCount: INTEGER): OSErr;
  181.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  182.     INLINE $303C, $0402, $ABF2;
  183.     {$ENDC}
  184. FUNCTION GetSpecificFreeThreadCount(threadStyle: ThreadStyle; stackSize: Size; VAR freeCount: INTEGER): OSErr;
  185.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  186.     INLINE $303C, $0615, $ABF2;
  187.     {$ENDC}
  188. FUNCTION GetDefaultThreadStackSize(threadStyle: ThreadStyle; VAR stackSize: Size): OSErr;
  189.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  190.     INLINE $303C, $0413, $ABF2;
  191.     {$ENDC}
  192. FUNCTION ThreadCurrentStackSpace(thread: ThreadID; VAR freeStack: UInt32): OSErr;
  193.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  194.     INLINE $303C, $0414, $ABF2;
  195.     {$ENDC}
  196. FUNCTION NewThread(threadStyle: ThreadStyle; threadEntry: ThreadEntryProcPtr; threadParam: UNIV Ptr; stackSize: Size; options: ThreadOptions; VAR threadResult: UNIV Ptr; VAR threadMade: ThreadID): OSErr;
  197.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  198.     INLINE $303C, $0E03, $ABF2;
  199.     {$ENDC}
  200. FUNCTION DisposeThread(threadToDump: ThreadID; threadResult: UNIV Ptr; recycleThread: BOOLEAN): OSErr;
  201.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  202.     INLINE $303C, $0504, $ABF2;
  203.     {$ENDC}
  204. FUNCTION YieldToThread(suggestedThread: ThreadID): OSErr;
  205.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  206.     INLINE $303C, $0205, $ABF2;
  207.     {$ENDC}
  208. FUNCTION YieldToAnyThread: OSErr;
  209.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  210.     INLINE $42A7, $303C, $0205, $ABF2;
  211.     {$ENDC}
  212. FUNCTION GetCurrentThread(VAR currentThreadID: ThreadID): OSErr;
  213.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  214.     INLINE $303C, $0206, $ABF2;
  215.     {$ENDC}
  216. FUNCTION GetThreadState(threadToGet: ThreadID; VAR threadState: ThreadState): OSErr;
  217.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  218.     INLINE $303C, $0407, $ABF2;
  219.     {$ENDC}
  220. FUNCTION SetThreadState(threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID): OSErr;
  221.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  222.     INLINE $303C, $0508, $ABF2;
  223.     {$ENDC}
  224. FUNCTION SetThreadStateEndCritical(threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID): OSErr;
  225.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  226.     INLINE $303C, $0512, $ABF2;
  227.     {$ENDC}
  228. FUNCTION SetThreadScheduler(threadScheduler: ThreadSchedulerProcPtr): OSErr;
  229.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  230.     INLINE $303C, $0209, $ABF2;
  231.     {$ENDC}
  232. FUNCTION SetThreadSwitcher(thread: ThreadID; threadSwitcher: ThreadSwitchProcPtr; switchProcParam: UNIV Ptr; inOrOut: BOOLEAN): OSErr;
  233.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  234.     INLINE $303C, $070A, $ABF2;
  235.     {$ENDC}
  236. FUNCTION SetThreadTerminator(thread: ThreadID; threadTerminator: ThreadTerminationProcPtr; terminationProcParam: UNIV Ptr): OSErr;
  237.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  238.     INLINE $303C, $0611, $ABF2;
  239.     {$ENDC}
  240. FUNCTION ThreadBeginCritical: OSErr;
  241.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  242.     INLINE $303C, $000B, $ABF2;
  243.     {$ENDC}
  244. FUNCTION ThreadEndCritical: OSErr;
  245.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  246.     INLINE $303C, $000C, $ABF2;
  247.     {$ENDC}
  248. FUNCTION SetDebuggerNotificationProcs(notifyNewThread: DebuggerNewThreadProcPtr; notifyDisposeThread: DebuggerDisposeThreadProcPtr; notifyThreadScheduler: DebuggerThreadSchedulerProcPtr): OSErr;
  249.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  250.     INLINE $303C, $060D, $ABF2;
  251.     {$ENDC}
  252. FUNCTION GetThreadCurrentTaskRef(VAR threadTRef: ThreadTaskRef): OSErr;
  253.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  254.     INLINE $303C, $020E, $ABF2;
  255.     {$ENDC}
  256. FUNCTION GetThreadStateGivenTaskRef(threadTRef: ThreadTaskRef; threadToGet: ThreadID; VAR threadState: ThreadState): OSErr;
  257.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  258.     INLINE $303C, $060F, $ABF2;
  259.     {$ENDC}
  260. FUNCTION SetThreadReadyGivenTaskRef(threadTRef: ThreadTaskRef; threadToSet: ThreadID): OSErr;
  261.     {$IFC TARGET_OS_MAC AND TARGET_CPU_68K AND NOT TARGET_RT_MAC_CFM}
  262.     INLINE $303C, $0410, $ABF2;
  263.     {$ENDC}
  264. {$ALIGN RESET}
  265. {$POP}
  266.  
  267. {$SETC UsingIncludes := ThreadsIncludes}
  268.  
  269. {$ENDC} {__THREADS__}
  270.  
  271. {$IFC NOT UsingIncludes}
  272.  END.
  273. {$ENDC}
  274.